package cc.vv.btpartyjob.partymanager.delegate

import android.annotation.SuppressLint
import android.view.View
import android.widget.AdapterView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import cc.vv.baselibrary.view.BCNoScrollListView
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.baselibrary.view.webview.BCWebView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.adapter.SocialOrganAdapter
import cc.vv.btpartyjob.partymanager.adapter.SocialOrganDynamicAdapter
import cc.vv.btpartyjob.partymanager.inter.OperationItemClickInterface
import cc.vv.btpartyjob.partymanager.view.QiShiYeDanWeiOperationView
import cc.vv.btpartyjob.partymanager.view.WangGeOperationView
import cc.vv.mvp.delegate.BaseAppDelegate
import cc.vv.party.beans.vo.OrgVO
import cc.vv.party.beans.vo.UnitVO
import java.util.*

/**
 * 社区大党委详情
 * Created by Chen.qi on 2018/10/24.
 */
class SheQuPartyDetailActivityDelegate : BaseAppDelegate() {


    override fun initWidget() {

    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_shequ_party_detial
    }

    /**设置标题title*/
    fun setTopBarTitle(topBarTitle: String?) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_asPd_topBar)
        titleBar?.setTitle(topBarTitle)
    }


    /**设置标题右边按钮点击事件*/
    fun setTitleBackBtnOnClick(event: BaseTopBarView.EventInterface) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_asPd_topBar)
        titleBar?.setEventInterface(event)
    }

    fun setWebViewContent(webStr: String?) {
        val webView = getView<BCWebView>(R.id.bv_bh5a_contentWeb)
        webView?.loadData(webStr, "text/html; charset=UTF-8", null)//这种写法可以正确解码
    }

    /**
     * 设置联系人信息
     */
    @SuppressLint("SetTextI18n")
    fun setPerInfo(prName: String?, prPhone: String?, isShow: Boolean) {
        val tvStr = getView<TextView>(R.id.tv_asPd_partyBrief)
        if (isShow) {
            tvStr?.text = "负责人：$prName    联系电话：$prPhone"
        } else {
            tvStr?.text = "负责人：$prName"
        }
    }

    /**
     * 设置网格数据
     */
    fun setSheQuPartyWangGe(optionList: ArrayList<OrgVO>?) {
        getView<WangGeOperationView>(R.id.ov_asPd_wangGeAll)?.addAllSelectedFileView(optionList, 4)
    }

    /**
     * 设置企事业单位数据
     */
    fun setEnterPriseData(optionList: ArrayList<UnitVO>) {
        getView<QiShiYeDanWeiOperationView>(R.id.ov_asPd_enterpriseAll)?.
                addAllSelectedFileView(optionList, 4)
    }

    /**
     * 设置社会组织和动态组织显示与否
     */
    fun setSocialSelected(socialSelected: Boolean) {
        val socialText = getView<TextView>(R.id.tv_asPd_SocialOrganization)
        val socialDynamicText = getView<TextView>(R.id.tv_asPd_SocialOrganizationDynamic)
        val socialList = getView<BCNoScrollListView>(R.id.blv_asPd_listView)
        val socialDynamicList = getView<BCNoScrollListView>(R.id.blv_asPd_listViewDynamic)
        socialText?.isSelected = socialSelected
        socialDynamicText?.isSelected = !socialSelected
        if (socialSelected) {
            socialList?.visibility = View.VISIBLE
            socialDynamicList?.visibility = View.GONE
        } else {
            socialList?.visibility = View.GONE
            socialDynamicList?.visibility = View.VISIBLE
        }
    }

    /**
     * 社会组织
     */
    fun setAdapterData(adapter: SocialOrganAdapter) {
        getView<BCNoScrollListView>(R.id.blv_asPd_listView)?.adapter = adapter

    }

    /**
     * 社会组织动态
     */
    fun setAdapterDataDynamic(adapter: SocialOrganDynamicAdapter) {
        getView<BCNoScrollListView>(R.id.blv_asPd_listViewDynamic)?.adapter = adapter
    }

    fun setListViewFocusFalse() {
        getView<BCNoScrollListView>(R.id.blv_asPd_listView)?.isFocusable = false
    }

    fun getSHZZ(): BCNoScrollListView {
        return getView(R.id.blv_asPd_listView)
    }

    fun getDynamic(): BCNoScrollListView {
        return getView(R.id.blv_asPd_listViewDynamic)
    }

    /**
     * 显示网格数据
     */
    fun setShowGrid(isShow: Boolean) {
        val viewWangGe = getView<RelativeLayout>(R.id.rl_asPd_wgAll)
        if (isShow) {
            viewWangGe?.visibility = View.VISIBLE
        } else {
            viewWangGe?.visibility = View.GONE
        }
    }

    /**
     * 显示企事业单位数据
     */
    fun setShowQiShiYeDanWei(isShow: Boolean) {
        val viewWangGe = getView<RelativeLayout>(R.id.rl_asPd_qiShiYeDanWeiAll)
        if (isShow) {
            viewWangGe?.visibility = View.VISIBLE
        } else {
            viewWangGe?.visibility = View.GONE
        }
    }

    /**
     * 显示社会组织
     */
    fun setShowSheHuiZuZhi(isShow: Boolean) {
        val viewWangGe = getView<RelativeLayout>(R.id.iv_asPd_sheHuiZuZhiAll)
        if (isShow) {
            viewWangGe?.visibility = View.VISIBLE
        } else {
            viewWangGe?.visibility = View.GONE
        }
    }

    /**
     * 显示无数据
     */
    fun setShowNoData(isShow: Boolean) {
        val viewNodata = getView<TextView>(R.id.btv_asPd_comNoData)
        if (isShow) {
            viewNodata?.visibility = View.VISIBLE
        } else {
            viewNodata?.visibility = View.GONE
        }
    }

    fun showWebData(isShow: Boolean) {
        val webTopShow = getView<LinearLayout>(R.id.ll_asPd_topWeb)
        if (isShow) {
            webTopShow?.visibility = View.VISIBLE
        } else {
            webTopShow?.visibility = View.GONE
        }
    }

}